using System;
using System.Collections.Generic;
using System.Text;
using Blazing.BusinessObjects.Cms;
using System.Diagnostics;

using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using ClassInitialize = NUnit.Framework.TestFixtureSetUpAttribute;
using ClassCleanup = NUnit.Framework.TestFixtureTearDownAttribute;

namespace BusinessObjectTests
{
    [TestClass]
    public class ImageTests : NHibernateInMemoryTestFixtureBase
    {
        private void CheckValues(Image obj, Image newObj)
        {
            Assert.AreEqual(obj.ID, newObj.ID);
            Assert.AreEqual(obj.AlternateText, newObj.AlternateText);
            Assert.AreEqual(obj.Description, newObj.Description);
            Assert.AreEqual(obj.ImageType.ID, newObj.ImageType.ID);
            Assert.AreEqual(obj.Name, newObj.Name);
            Assert.AreEqual(obj.RowStamp, newObj.RowStamp);
        }

        [TestMethod]
        public void CreateImage()
        {
            Image obj = BusinessObjectFactory.CreateAndFillImage();
            ImageType type = BusinessObjectFactory.CreateAndFillImageType();
            type.Save();

            obj.ImageType = type;
            obj.Save();

            Image obj2 = Image.Load(obj.ID);
            Assert.IsNotNull(obj2);

            CheckValues(obj, obj2);

            obj.Delete();
            obj.Save();
            type.Delete();
            type.Save();
        }

        [TestMethod]
        public void TestPropertyChanged()
        {
            Image img = BusinessObjectFactory.CreateAndFillImage();
            img.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(img_PropertyChanged);
            img.Name = "New name";
        }

        void img_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            Trace.WriteLine(e.PropertyName + " has changed");
        }
    }
}
